uniform sampler2D bottomTexture;
uniform sampler2D currentTexture;
uniform float compositingLevel;
uniform float thresholdLevel;

void main()
{
    vec4 bottomTexValue = texture2D(bottomTexture, gl_TexCoord[0].xy);
    
    vec4 currentTexValue = texture2D(currentTexture, gl_TexCoord[0].xy);
    
    vec4 finalResult;
    
    if(bottomTexValue.a > thresholdLevel)
        finalResult = (1.0 - compositingLevel)*currentTexValue + 
            compositingLevel*bottomTexValue;
    else
        finalResult = currentTexValue;
    
    gl_FragColor = finalResult;
}